package com.skyblue.statemachine.config;

import com.skyblue.statemachine.form.Form;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.guard.Guard;

/**
 * DEAL_CHOICE guard
 *
 * @author wphmoon
 */
public class ComplexFormDealChoiceGuard implements Guard<ComplexFormStates, ComplexFormEvents> {

    @Override
    public boolean evaluate(StateContext<ComplexFormStates, ComplexFormEvents> context) {
        System.out.println("ComplexFormDealChoiceGuard!!!!!!!!!!!!!");
        Form form = context.getMessage().getHeaders().get("form", Form.class);
        assert form != null;
        boolean returnValue = (form.getFormName() != null) && (!form.getFormName().contains("坏"));

        System.out.println(form + " is " + returnValue);
        return returnValue;
    }

}
